﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace shfa.snomtastic.systray.components
{
    public partial class ThreeStateButtonBackup : UserControl
    {

        public Bitmap ImageUp { get; set; }
        public Bitmap ImageDown { get; set; }
        public Bitmap ImageOver { get; set; }
        public string Title { get; set; }
        public Font TitleFont { get; set; }


        public ThreeStateButtonBackup(Bitmap imageUp, Bitmap imageDown, Bitmap imageOver, string title, string text)
        {
            this.Name = "ThreeStateButton";
            this.Size = new System.Drawing.Size(238, 50);
            this.BackColor = System.Drawing.Color.Transparent;

            this.ImageUp = imageUp;
            this.ImageDown = imageDown;
            this.ImageOver = imageOver;
            this.Title = title;
            this.Text = text;


            initControls();
        }


        private void initControls()
        {
            this.BackgroundImage = this.ImageUp;

            this.MouseEnter += new EventHandler(ThreeStateButton_MouseEnter);
            this.MouseDown += new MouseEventHandler(ThreeStateButton_MouseDown);
            this.MouseLeave += new EventHandler(ThreeStateButton_MouseLeave);
        }


        void ThreeStateButton_MouseHover(object sender, EventArgs e)
        {
            if (this.ImageOver != null)
            {
                this.BackgroundImage = this.ImageOver;
            }
        }

        void ThreeStateButton_MouseUp(object sender, MouseEventArgs e)
        {
            if (this.ImageOver != null)
            {
                this.BackgroundImage = this.ImageOver;
            }
        }



        void ThreeStateButton_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.ImageDown != null)
            {
                this.BackgroundImage = ImageDown;
            }
        }

        void ThreeStateButton_MouseLeave(object sender, EventArgs e)
        {
            if (this.ImageUp != null)
            {
                this.BackgroundImage = this.ImageUp;
            }

        }

        void ThreeStateButton_MouseEnter(object sender, EventArgs e)
        {
            if (this.ImageOver != null)
            {
                this.BackgroundImage = this.ImageOver;
            }
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            if (BackgroundImage != null)
            {
                Graphics offScreenGraphics;
                Bitmap offscreenBitmap;
                offscreenBitmap = new Bitmap(BackgroundImage.Width, BackgroundImage.Height);
                offScreenGraphics = Graphics.FromImage(offscreenBitmap);
                offScreenGraphics.DrawImage(BackgroundImage, 0, 0, BackgroundImage.Width, BackgroundImage.Height);
                DrawText(offScreenGraphics);
                e.Graphics.DrawImage(offscreenBitmap, 0, 0);
            }
        }

        private void DrawText(Graphics g)
        {
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Near;
            sf.LineAlignment = StringAlignment.Center;
            sf.FormatFlags = StringFormatFlags.NoWrap;
            sf.Trimming = StringTrimming.EllipsisCharacter;
            //g.DrawString(this.Text, new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold), new SolidBrush(Color.FromArgb(42, 61, 88)), new Point(44, 8));
            if (this.TitleFont== null)
                this.TitleFont = this.Font;
            if (this.Title != string.Empty | this.Title != null)
                g.DrawString(this.Title, this.TitleFont, new SolidBrush(this.ForeColor), new Point(44, 7));
            if (this.Text != string.Empty | this.Text != null)
                g.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), new Point(44, 32));

        }

    }
}
